<!-- 药品调价备用-->
<template>
  <div class="app-container">
  <sn-card-with-title>
    <drug-change-price-title
      @drugChangePrice="showChangePriceTable"
      @drugChangePriceRecord="showChangePriceRecordTable"
      slot="title"/>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="登录地址" prop="ipaddr">
        <el-input
          v-model="queryParams.ipaddr"
          placeholder="请输入登录地址"
          clearable
          size="small"
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名称"
          clearable
          size="small"
          style="width: 240px;"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


        <el-form-item label="状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="登录状态"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>


      <el-form-item label="登录时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <div slot="content">

      <drug-change-price-find-info-bar
        @getValue="getSelectValue"
        @getInputValue="getInputValue"/>
      <!-- 药品调价表格 -->
      <drug-change-price-table
        v-if="!showChangePriceRecord"
        :table-data="drugPriceChangeTableData"/>
      <!-- 药品调价记录表格 -->
      <drug-change-price-record-table
        v-else
        :table-data="drugPriceChangeRecordTableData"/>
    </div>
  </sn-card-with-title>


  </div>
</template>

<script>
import DrugChangePriceFindInfoBar from "./children/DrugChangePriceFindInfoBar";
import DrugChangePriceTable from "./children/DrugChangePriceTable";
import DrugChangePriceTitle from "./children/DrugChangePriceTitle";
import DrugChangePriceRecordTable from "./children/DrugChangePriceRecordTable";


//导入所有调价首页信息方法
import {getTypeDrug,getAllDrug,getLikeDrug} from "@/api/drug_manage/drugManage";


export default {
  name: "PricingN",
  dicts: ['prescription_type'],
  data() {
    return {
      drugPriceChangeTableData:[] ,
      drugPriceChangeRecordTableData:[] ,
      showChangePriceRecord: false,
      queryParams:{

      }
    }
  },
  components: {
    DrugChangePriceFindInfoBar,
    DrugChangePriceTable,
    DrugChangePriceTitle,
    DrugChangePriceRecordTable
  },
  methods: {
    showChangePriceTable() {
      this.showChangePriceRecord = false
    },
    showChangePriceRecordTable() {
      getAllDrug().then(res => {
        console.log(res);
        this.drugPriceChangeRecordTableData = res.rows;
        // for (let i=0;i<res.rows.length;i++){
        //   this.$set(this.drugPriceChangeRecordTableData[i],'ids',i+1)
        // }

      })
      this.showChangePriceRecord = true
    },
    //获取所有药品
    getAllDrug(){
      if(!this.showChangePriceRecord){
        getAllDrug().then(res => {
          // console.log(res);
          this.drugPriceChangeTableData=res.rows;
          console.log( "drugPriceChangeTableData:",this.drugPriceChangeTableData)
          // for (let i=0;i<res.rows.length;i++){
          //   this.$set(this.drugPriceChangeTableData[i],'ids',i+1)
          // }
        })
      }else {
        getAllDrug().then(res => {
          // console.log(res);
          this.drugPriceChangeRecordTableData = res.rows;
          console.log("drugPriceChangeRecordTableData:",this.drugPriceChangeRecordTableData)
          // for (let i=0;i<res.rows.length;i++){
          //   this.$set(this.drugPriceChangeRecordTableData[i],'ids',i+1)
          // }

        })
      }
    },
    //获取对应类型的药品
    getSelectValue(value){
      if(value.value === 2){
        this.getAllDrug();
      }else{

        getTypeDrug(value.value).then(res => {
          if(!this.showChangePriceRecord){
            this.drugPriceChangeTableData=res.rows;
            // for (let i=0;i<res.rows.length;i++){
            //   this.$set(this.drugPriceChangeTableData[i],'ids',i+1)
            // }
          }else{
            this.drugPriceChangeRecordTableData=res.rows;
            // for (let i=0;i<res.rows.length;i++){
            //   this.$set(this.drugPriceChangeRecordTableData[i],'ids',i+1)
            // }
          }
        })
      }
    },
    //模糊查询
    getInputValue(inputValue){
      if(inputValue===null || inputValue===''){
        this.getAllDrug()
      }else{
        getLikeDrug(inputValue).then(res => {
          if(!this.showChangePriceRecord){
            this.drugPriceChangeTableData=res.rows;
            // for (let i=0;i<res.rows.length;i++){
            //   this.$set(this.drugPriceChangeTableData[i],'ids',i+1)
            // }
          }else{
            this.drugPriceChangeRecordTableData=res.rows;
            // for (let i=0;i<res.rows.length;i++){
            //   this.$set(this.drugPriceChangeRecordTableData[i],'ids',i+1)
            // }
          }
        })
      }
    }
  },
  created() {

    this.getAllDrug()
  }
}
</script>

<style scoped>

</style>
